package com.dr.controller;

import com.dr.pojo.User;
import com.dr.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private LoginService service;
    @RequestMapping("/login")
    public String login(User user, HttpSession session, Model model){
        User loginUser = service.findUser(user);
        if(loginUser == null){
            //登陆失败， 退回登陆页面
            model.addAttribute("loginErrorMessage", "用户名或密码错误，请重试！");
//            return "login.html";
            return "login.html";
        }else{
            session.setAttribute("loginUser", loginUser); //记录登陆用户session
            return "dashboard.html";
        }

    }
}
